﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using COP.Extensions;

namespace COP.Objects.Maps
{
    public class MAP : MAPBase
    {

        public override void Append(object data)
        {
            XmlNode xmlNode = (XmlNode)data;
            foreach (XmlAttribute attrib in xmlNode.Attributes)
            {
                switch (attrib.Name)
                {
                    case Constant.Config.Key:
                        this.key = xmlNode.GetAttributeValue(Constant.Config.Key);
                        break;
                    case Constant.Config.Value:
                        this.Value = xmlNode.GetAttributeValue(Constant.Config.Value);
                        break;
                    case Constant.Config.Method:
                        this.method = xmlNode.GetAttributeValue(Constant.Config.Method);
                        break;
                    default:
                        if (this.otherKeys == null)
                            this.otherKeys = new List<MAPBase>();
                        this.otherKeys.Add(new MAP { key = attrib.Name, Value = xmlNode.GetAttributeValue(attrib.Name) });
                        break;
                }
            }
        }

        public override object Process()
        {
            OnMapProcess();
            OnProcessed();
            return this.Value;

        }

        protected virtual void OnProcessed()
        {

        }
    }



    
}
